<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration {
    public function up(): void
    {
        Schema::create('users', function (Blueprint $table) {
            $table->id();
            $table->application();
            $table->unsignedBigInteger('wechat_id')
                ->index();
            $table->string('openid', 32);
            $table->string('nickname')
                ->nullable();
            $table->string('avatar')
                ->nullable();
            $table->boolean('lock')
                ->default(false);
            $table->timestamps();

            $table->unique(['application_id', 'wechat_id', 'openid']);
        });
    }

    public function down(): void
    {
        Schema::dropIfExists('users');
    }
};
